home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Mousetools / HeliosMouse / Helios-Handler.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  5KB  |  140 lines

  1. /*
  2.  *  Helio-Handler.c     Input Handler for HeliosMouse.  Helios-handler
  3.  *                      calls ActivateWindow() whenever the mouse moves
  4.  *                      over a new window.
  5.  *
  6.  *              Copyright (c) 1987 by Davide P. Cervone
  7.  *  You may use this code provided this copyright notice is left intact.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <devices/inputevent.h>
  12. #include <intuition/intuitionbase.h>
  13.  
  14. static char *version = "Helios-Handler v1.1 (August 1987)";
  15. static char *author  = "Copyright (c) 1987 by Davide P. Cervone";
  16.  
  17. extern struct Layer *WhichLayer();
  18. extern void myHandlerStub();
  19.  
  20. /*
  21.  *  The window associated with a given Layer structure.
  22.  */
  23. #define WINDOW(layer)   ((struct Window *)((layer)->Window))
  24.  
  25. /*
  26.  *  The top line of a screen (in INTERLACED lines)
  27.  */
  28. #define SCREENTOP\
  29.    (theScreen->TopEdge << ((theScreen->ViewPort.Modes & LACE)? 0: 1))
  30.  
  31. /*
  32.  *  The mouse button qualifiers
  33.  */
  34. #define BUTTONSDOWN     (IEQUALIFIER_LEFTBUTTON | IEQUALIFIER_RBUTTON)
  35.  
  36.  
  37. struct IntuitionBase *IntuitionBase = NULL;
  38. struct LayersBase    *LayersBase    = NULL;
  39. struct SysBase       *SysBase       = NULL;
  40.  
  41. /*
  42.  *  Setup()
  43.  *
  44.  *  HeliosMouse calls LoadSeg() to get this handler into memory.  The segment
  45.  *  that it gets points to this routine.  HeliosMouse calls Setup() and 
  46.  *  passes the IntuitionBase, LayersBase and SysBase pointers that it
  47.  *  has initialized (with OpenLibrary()).  Setup returns a pointer to
  48.  *  the actual input handler, which HeliosMouse installs.
  49.  */
  50.  
  51. long Setup(Ibase,Lbase,Sbase)
  52. struct IntuitionBase *Ibase;
  53. struct LayersBase *Lbase;
  54. struct SysBase *Sbase;
  55. {
  56.    IntuitionBase = Ibase;
  57.    LayersBase = Lbase;
  58.    SysBase = Sbase;
  59.    return((long) &myHandlerStub);
  60. }
  61.  
  62.  
  63. /*
  64.  *  myHandler()
  65.  *
  66.  *  This is the input handler.  Whenever a mouse move or a keyboard event
  67.  *  occurs, we check to see if the mouse is over an inactive window, and
  68.  *  if so, we activate that window.
  69.  *
  70.  *  To do this, we get the current absolute Y position of the mouse and
  71.  *  look through the Intuition screens for the first one that is closer
  72.  *  to the top of the View than the mouse is (i.e., the first one that is
  73.  *  high enough to be under the mouse).  Note that we must convert non-
  74.  *  interlace screen coordinates to interlaces ones in order to be able
  75.  *  to compare them to the mouse position (the SCREENTOP macro does this).
  76.  *  If no screen is found (this should never happen, but just in case), then 
  77.  *  just use the currently active one.
  78.  *
  79.  *  From the selected screen we get the mouse x and y position (if it's a 
  80.  *  mouse move, we add the event offsets to find the new mouse position).  
  81.  *  Using these, we call WhichLayer(), which tells us which Layer within 
  82.  *  that screen the mouse was pointing at.  If that layer has a window and 
  83.  *  that window is not currently the active window, we activate it.
  84.  *
  85.  *  When we're all through looking at events, we pass the list on, so that
  86.  *  Intuition (and any other handlers) can do their thing.
  87.  *
  88.  *  Compile this section with -dKEY_ONLY to have windows activate only when 
  89.  *  a key is pressed (not when the mouse moves over an inactive one).
  90.  */
  91.  
  92. struct InputEvent *myHandler(EventList,data)
  93. struct InputEvent *EventList;
  94. APTR data;
  95. {
  96.    register struct InputEvent *theEvent = EventList;
  97.    register struct Layer  *theLayer;
  98.    register struct Window *theWindow;
  99.    register struct Screen *theScreen;
  100.    register long x,y;
  101.  
  102.    Forbid();
  103.    while(theEvent)
  104.    {
  105.       if (
  106.           #ifndef KEY_ONLY
  107.             (theEvent->ie_Class == IECLASS_RAWMOUSE &&
  108.             (theEvent->ie_X != 0 || theEvent->ie_Y != 0) &&
  109.             (theEvent->ie_Qualifier & BUTTONSDOWN) == 0) ||
  110.           #endif
  111.             (theEvent->ie_Class == IECLASS_RAWKEY)
  112.          )
  113.       {
  114.          y = IntuitionBase->MouseY;
  115.          theScreen = IntuitionBase->FirstScreen;
  116.          while (theScreen && y < SCREENTOP) theScreen = theScreen->NextScreen;
  117.          if (theScreen == NULL) theScreen = IntuitionBase->ActiveScreen;
  118.  
  119.          x = theScreen->MouseX;
  120.          y = theScreen->MouseY;
  121.          #ifndef KEY_ONLY
  122.             if (theEvent->ie_Class == IECLASS_RAWMOUSE)
  123.             {
  124.                x += theEvent->ie_X;
  125.                y += theEvent->ie_Y;
  126.             }
  127.          #endif
  128.  
  129.          theLayer = WhichLayer(&(theScreen->LayerInfo),x,y);
  130.          if (theLayer && (theWindow = WINDOW(theLayer)))
  131.             if (theWindow != IntuitionBase->ActiveWindow)
  132.                ActivateWindow(theWindow);
  133.       }
  134.       theEvent = theEvent->ie_NextEvent;
  135.    }
  136.    Permit();
  137.    return(EventList);
  138. }
  139.  
  140.